package com.example.a2209_shop.adapter

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.widget.LinearLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.a2209_shop.R
import com.example.base.entity.CateEntity

class OneAdapter:BaseQuickAdapter<CateEntity,BaseViewHolder>(R.layout.item_one) {
    //记录选中的item --id
    private var selectedId = 1
    override fun convert(holder: BaseViewHolder, item: CateEntity) {
        holder.setText(R.id.one_tv,item.category_name)
        holder.getView<LinearLayout>(R.id.one_ll).background = if(item.id==selectedId){
            ColorDrawable(Color.RED)
        }else null
    }
    //更新选中的item的id
    fun setId(id:Int){
        selectedId = id
        notifyDataSetChanged()
    }
}